package chaoyue.study.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ResourceBundle;

/**
 * 获取连接
 * 使用配置文件来存放连接参数，方便快速更换数据库
 */
public class Test1_GetConnection4 {
    public static void main(String[] args) throws Exception {
        // 加载配置文件 读取配置
        ResourceBundle resource = ResourceBundle.getBundle("jdbc");
        String url = resource.getString("url");
        String username = resource.getString("username");
        String password = resource.getString("password");
        String driver = resource.getString("driver");

        // 加载驱动
        Class.forName(driver);
        // 获取连接
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(connection);
    }
}
